#!/bin/bash

# ----------------------------------------------------------------------
# Filename:   setfacl1.sh
# Version:    1.0
# Date:       2013/11/28
# Author:     huijing.hei
# Email:      huijing.hei@cs2c.com.cn
# Summary:    03系统安全功能-05ACL-01命令setfacl-01设置属性
# Notes:       ***
# Copyright:    China Standard Software Co., Ltd.
# History：     
#             Version 1.0, 2013/11/28
#             - setfacl.
# ----------------------------------------------------------------------

##! @TODO: setfacl
##! @AUTHOR: huijing.hei
##! @VERSION: 1.0 
##! @OUT: 0 => success; 1 => failure

function DoTest()
{
    trap DoCleanup EXIT INT 

    CmdCheck setfacl getfacl

    TEST_USER=acltest
    TEST_USER_PASSWORD=setfacl123
    TMP_FILE=/tmp/acltest$$

    AddUserPasswd "${TEST_USER}" "${TEST_USER_PASSWORD}"
    EchoResult "add user ${TEST_USER}"

    # touch tmp file
    echo "test" > ${TMP_FILE}

    # setfacl
    setfacl -m ${TEST_USER}:rw- ${TMP_FILE}
    EchoResult "setfacl -m "

    # getfacl
    getfacl -p ${TMP_FILE} | grep "user:${TEST_USER}:rw-"
    EchoResult "getfacl"

    # ls -l
    ls -l ${TMP_FILE} | grep '+'
    EchoResult "ls ${TMP_FILE}"
    

}


##! @TODO: setfacl
##! @AUTHOR: huijing.hei
##! @VERSION: 1.0 
##! @OUT: 0 => success; 1 => failure

function DoCleanup()
{
    id -ru ${TEST_USER} > /dev/null 2>&1 && userdel -r ${TEST_USER}
    [ -f ${TMP_FILE} ] && rm -f ${TMP_FILE}
}

# include lib files

if [ -z "$SFROOT" ]
then
    echo "SFROOT is null, pls check"
    exit 1
fi

. ${SFROOT}/lib/Echo.sh
. ${SFROOT}/lib/Check.sh
. ${SFROOT}/testcases/Security/lib/UserOps.sh

export LANG=C

DoTest
EchoResult "testcase: setfacl"
echo ""
